package com.mapper;

import com.pojo.Admin;
import com.pojo.Notice;
import com.pojo.Teacher;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Timestamp;
import java.util.List;
import com.pojo.fileData;

@Mapper
public interface fileMapper {

//    @Select("SELECT * FROM fileinf where student_id = (SELECT stunum FROM student WHERE teacher_id = (SELECT teacher_id FROM teacher where jobnum = #{id}}) )")
//    String[] getfileData(Integer id);

    @Select("SELECT file_address FROM fileinf WHERE student_id = #{id}")
    String getfileAddress(Integer id);

    @Insert("insert into fileinf (annex,id,releaseTime,sender) values (#{s},#{s1},#{d},#{name})")
    void insertFileName(String s,Integer s1,Timestamp d,String name);

    @Select("SELECT stunum FROM student WHERE teacher_id = (SELECT teacher_id FROM teacher where jobnum = #{id})")
    Integer getStudentId(Integer id);

    @Select("SELECT nickname FROM student WHERE teacher_id = (SELECT teacher_id FROM teacher where jobnum = #{id})")
    String getStudentName(Integer id);

//    @Insert("insert into fileinf (student_id) values (#{studentid}) ")
//    void insertStudentId(String studentid);
//
//    @Insert("insert into fileinf (student_name) values (#{studentName})")
//    void insertStudentName(String studentName);

    @Insert("insert into student (uploadTime) values (#{d})")
    void insertCurrentTime(Timestamp d);

    @Update("update fileinf set time = #{d}")
    void updateCurrentTime(Timestamp d);

    @Select("select nickname from student where open_id = #{id}")
    String seletStudentById(Integer id);

    @Select("select * from fileinf")
    List<fileData> getfileInfo(Integer page,Integer pageSize);

    //---------------------------------------
    @Select("select * from fileinf order by releaseTime desc limit #{page},#{pagesize}")
    List<fileData> getAll(Integer page, Integer pagesize);

    @Select("select count(*) from fileinf")
    Integer countAll();

    @Select("select * from fileinf where sender = #{sender} and type = #{type} order by releaseTime desc limit #{page},#{pagesize}")
    List<fileData> getList(Integer sender,Integer type,Integer page,Integer pagesize);

    @Select("select count(*) from fileinf where sender = #{sender} and type = #{type}")
    Integer countList(Integer sender,Integer type);

    @Select("select * from teacher where id = #{id}")
    Teacher getTeacherById(Integer id);

    @Select("select * from admin where id = #{id}")
    Admin getAdminById(Integer id);
}
